<?php
/**
 * Created by litong on Date: 2019/2/23 0023 下午 8:59
 * 从配置文件读取信息并连接
 */
$dir = dirname(__FILE__ )."/config/config.ini";
echo "dir:".$dir.PHP_EOL;
$configFilePath=realpath($dir);
echo "文件路径是:".$configFilePath,PHP_EOL;
try{
  //解析config.ini文件
  $config=parse_ini_file($configFilePath);
  //对mysqli类进行实例化
  $connection = new mysqli($config['host'], $config['username'], $config['password'], $config['dbname']);
  if(mysqli_connect_errno()){ //判断是否连接上mysql数据库
    echo "连接失败".mysqli_connect_errno().":".mysqli_connect_error(),PHP_EOL;
  }else{
    echo "连接成功",PHP_EOL;
  }
}catch(Exception $e){//捕获异常
  $e->getMessage();
}